<?php

namespace App\Http\Middleware;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ServerRequestInterface;
use App\Core\AppKey;
use Hyperf\Contract\ContainerInterface;
use Hyperf\HttpServer\Contract\RequestInterface;

/**
 * http 请求核心控制器
 * @author lihaiping
 */
class Core implements MiddlewareInterface
{
    protected $request = null;
    
    function __construct(RequestInterface $request)
    {
        $this->request = $request;
    }
    
    /**
     * {@inheritDoc}
     * @see \Psr\Http\Server\MiddlewareInterface::process()
     */
    function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        setContext(AppKey::CONTEXT_HTTP_REQUEST, $this->request);
        return $handler->handle($request);
    }
}
